﻿<UserControl x:Class="SharePointCSVImporter.RuleEditors.ExternalLookupReplace"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="420" d:DesignWidth="480">
 
        <Grid x:Name="LayoutRoot" Background="White" >
        <Grid.ColumnDefinitions>
            <ColumnDefinition MinWidth="200" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="45" />
      
            <RowDefinition />
        </Grid.RowDefinitions>
        <TextBlock  Margin="10" TextDecorations="Underline" FontSize="14" HorizontalAlignment="Center" Width="173" >External Lookup Replace</TextBlock>

        <Button Content="Instructions" Grid.Column="1"  VerticalAlignment="Center"  Click="Button_Click"  >

        </Button>
        <Popup Name="InstructionsPopup" >
            <Border BorderBrush="Black" BorderThickness="2">
                <Border.Effect>
                    <DropShadowEffect />
                </Border.Effect>
                <Grid Background="White">
                    <Grid.RowDefinitions >
                        <RowDefinition Height="18" />
                        <RowDefinition Height="130" />
                    </Grid.RowDefinitions>
                    <Button Name="InstructionCloseBtn" Click="InstructionCloseBtn_Click" Content="X" HorizontalAlignment="Right" Width="16" Height="18" VerticalAlignment="Top"></Button>
                    <TextBlock  Grid.Row="1"  Width="300"   TextWrapping="Wrap"  Grid.ColumnSpan="2"  Margin="10">
        	<Underline>
        		<Run Text="Instructions for External Lookup: "/>
        	</Underline>
        	System will attempt to replace this column's value with a lookup in a sharepoint list. 
            To do this, you will need to provide a web url, i.e. <Italic>http://site/</Italic> and a list name. Then provide up to three column names from this csv row to map and serve as a filter.  You must provide at least one filter map.
            Next, provide the list fields you want to replace this column's value with.  Finally, provide instructions on what to do if no records exist or multiple records return per filter.
                    </TextBlock>
                </Grid>
            </Border>
        </Popup>
        <Grid Grid.Row="1" Grid.ColumnSpan="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions >
                <RowDefinition Height="30"   />
                <RowDefinition Height="40"  />
                <RowDefinition Height="20"  />
                <RowDefinition Height="20"  />
                <RowDefinition Height="40"  />
                <RowDefinition Height="20"  />
                <RowDefinition Height="40"  />
                <RowDefinition Height="20"  />
                <RowDefinition Height="40"  />
                <RowDefinition   />
            </Grid.RowDefinitions>
            <StackPanel Orientation="Horizontal" Grid.ColumnSpan="1" HorizontalAlignment="Center">
                <TextBlock HorizontalAlignment="Right" Text="List Url:" Height="30" VerticalAlignment="Bottom"></TextBlock>
                <TextBox Name="WebUrlBox" MinWidth="150" BorderBrush="LightGray" BorderThickness="1" Text="{Binding Path=WebUrl, Mode=TwoWay}" />
            </StackPanel>
            <StackPanel Orientation="Horizontal" Grid.Column="1" HorizontalAlignment="Center">
                <TextBlock HorizontalAlignment="Right" Text="List Name:" Height="30" VerticalAlignment="Bottom"></TextBlock>
                <TextBox Name="ListNameBox" MinWidth="150" BorderBrush="LightGray" BorderThickness="1" Text="{Binding Path=ListName, Mode=TwoWay}" />
            </StackPanel>

            <StackPanel Orientation="Horizontal"  Grid.Row="1" Grid.ColumnSpan="2" Margin="10"  >
                <Button VerticalContentAlignment="Top" Margin="0,0,10,0" Content="{Binding Path=FieldRetreivalStatus,Mode=TwoWay}" Name="GetFieldsButton" Click="GetFieldsButton_Click"/>
                <TextBlock Text="Set this Column's Value to field: " VerticalAlignment="Bottom" ></TextBlock>
                
                <ComboBox Name="ValueFieldComboBox" MinWidth="150" ItemsSource="{Binding Path=SourceListFields}" DisplayMemberPath="StaticName" SelectedValuePath="InternalName" SelectedValue="{Binding Path=TargetFieldName, Mode=TwoWay}" />
              </StackPanel>


            <TextBlock Grid.Row="2" Grid.ColumnSpan="2" FontSize="14" FontWeight="Bold" TextDecorations="Underline" HorizontalAlignment="Center">When Fields/Columns Match</TextBlock>
            <StackPanel Orientation="Horizontal" Grid.Row="3" >
                <TextBlock   FontWeight="Bold" HorizontalAlignment="Center" Margin="10,0,0,0" VerticalAlignment="Bottom">SharePoint Field</TextBlock> 
                
            </StackPanel>

            <TextBlock Grid.Row="3" Grid.Column="1" VerticalAlignment="Bottom"  FontWeight="Bold" HorizontalAlignment="Center">CSV Column</TextBlock>

            <StackPanel Orientation="Horizontal" Grid.Row="4" Grid.ColumnSpan="2" Margin="10">
                <TextBlock Text="List Field: "></TextBlock>
                <ComboBox Name="ListFieldOne" MinWidth="150" ItemsSource="{Binding Path=SourceListFields}" DisplayMemberPath="StaticName" SelectedValuePath="InternalName" SelectedValue="{Binding Path=FieldName1, Mode=TwoWay}" />               
                <TextBlock Text=" = CSV Column "></TextBlock>
                <ComboBox Name="FieldSComboBox" MinWidth="100" ItemsSource="{Binding Path=AvailableColumns}" SelectedItem="{Binding Path=CsvColumn1, Mode=TwoWay}" />
            </StackPanel>
            <TextBlock Grid.Row="5" Grid.ColumnSpan="2" FontSize="14" FontWeight="Bold" HorizontalAlignment="Center">And</TextBlock>
            <StackPanel Orientation="Horizontal" Grid.Row="6" Grid.ColumnSpan="2" Margin="10">
                <TextBlock Text="List Field: "></TextBlock>
                <ComboBox Name="ListFieldTwo" MinWidth="150" ItemsSource="{Binding Path=SourceListFields}" DisplayMemberPath="StaticName" SelectedValuePath="InternalName" SelectedValue="{Binding Path=FieldName2, Mode=TwoWay}" />
                <TextBlock Text=" = CSV Column "></TextBlock>
                <ComboBox Name="FieldSComboBox2" MinWidth="100" ItemsSource="{Binding Path=AvailableColumns}" SelectedItem="{Binding Path=CsvColumn2, Mode=TwoWay}" />
            </StackPanel>
            <TextBlock Grid.Row="7" Grid.ColumnSpan="2" FontSize="14" FontWeight="Bold" HorizontalAlignment="Center">And</TextBlock>
            <StackPanel Orientation="Horizontal" Grid.Row="8" Grid.ColumnSpan="2" Margin="10">
                <TextBlock Text="List Field: "></TextBlock>
                <ComboBox Name="ListFieldThree" MinWidth="150" ItemsSource="{Binding Path=SourceListFields}" DisplayMemberPath="StaticName" SelectedValuePath="InternalName" SelectedValue="{Binding Path=FieldName3, Mode=TwoWay}" />     
                <TextBlock Text=" = CSV Column "></TextBlock>
                <ComboBox Name="FieldSComboBox3" MinWidth="100" ItemsSource="{Binding Path=AvailableColumns}" SelectedItem="{Binding Path=CsvColumn3, Mode=TwoWay}" />
            </StackPanel>
            
    
            <StackPanel Grid.Row="9" Margin="10,0,0,10" Grid.ColumnSpan="2" >
                <TextBlock>Options</TextBlock>
                <CheckBox IsChecked="{Binding Path=UseFirstIfMulti, Mode=TwoWay}" Name="UseFirstIfMultipleCheckBox">If more than one record maps to the filter, use first record's value.</CheckBox>
                <CheckBox IsChecked="{Binding Path=BlankIfNull, Mode=TwoWay}" Name="UseBlankValueIfNotFoundCheckBox">If no records match, save blank value? (Otherwise existing value  will be used)</CheckBox>
            </StackPanel>
        </Grid>
    </Grid> 

</UserControl>
